#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include "lab52.h"


int main()
{
    int operate;
    GoodsList *goodslist;
    GoodsInfo tempGood;
    init_list(&goodslist);
    char goods_id[MAX_ID_LEN + 5];
    bool flag = true;
    while (flag)
    {

        printf("1.显示所有商品的信息\n");
        printf("2.修改某个商品的信息\n");
        printf("3.插入某个商品的信息\n");
        printf("4.删除某个商品的信息\n");
        printf(" 5.查找某个商品的信息\n");
        printf(" 6.商品存盘并退出系统\n");
        printf("7.对商品价格进行排序\n");
        printf(" 8.(慎用)删除所有内容\n");
        printf("存盘并退出系统\n");

        /**
         * 
         *  1.显示所有商品的信息
            2.修改某个商品的信息
            3.插入某个商品的信息
            4.删除某个商品的信息
            5.查找某个商品的信息
            6.商品存盘并退出系统
            7.对商品价格进行排序
            8.(慎用)删除所有内容
         */
        scanf("%d", &operate);
        switch (operate)
        {
        case 1:
            output_all_items(goodslist);
            break;
        case 2:
            read_line(goods_id, MAX_ID_LEN);
            change_item(goodslist, goods_id, read_goods_info());
            break;
        case 3:
            tempGood = read_goods_info();
            int choice;
            scanf("%d", &choice);
            insert_item(goodslist, tempGood, choice);
            break;
        case 4:
            read_line(goods_id, MAX_ID_LEN);
            delete_item(goodslist, goods_id);
            break;
        case 5:
            read_line(goods_id, MAX_ID_LEN);
            search_item(goodslist, goods_id);
            break;
        case 6:
            save_to_file(goodslist);
            return 0;
            break;
        case 7:
            bubble_sort(goodslist);
            break;
        case 8:
            destory_list_and_file(goodslist);
            flag = false;
            break;
        default:
            flag = false;
        }
    }
    destory_list(&goodslist);
    return 0;
}